/*
@auther fenglei
*/
package xxhttp

import (
	"gitee.com/fenglei-l/ops-util/xxlog"
	"github.com/bytedance/sonic"
	"github.com/gogf/gf/v2/util/gconv"
	"github.com/valyala/fasthttp"
	"time"
)

type TBaseResultsWeb struct {
	B        bool
	HttpCode int
	Code     interface{} `json:"code"`
	Result   interface{} `json:"result"`
	Msg      string      `json:"msg"`
}
type TBaseResults struct {
	B        bool
	HttpCode int
	Code     string      `json:"code"`
	Message  interface{} `json:"message"`
}

const timeOut = 60 * time.Second

func HttpInterfaceReq(postUrl string, data ...interface{}) (t *TBaseResults) {
	t = new(TBaseResults)
	t.B = true
	client := NewHttpClient()
	client.ContentType = HttpContentTypeJson
	client.Method = fasthttp.MethodPost
	client.TimeOut = timeOut
	message := client.HttpRequestRetry(postUrl, data...)
	xxlog.InfoUp366("HttpInterfaceReq", postUrl, message)
	t.HttpCode = message.Code
	if message.Err != nil {
		t.B = false
		t.Code = "error"
		t.Message = message.Err.Error()
		return
	} else {
		if err := sonic.UnmarshalString(message.Body, &t); err != nil {
			t.B = false
			t.Code = "error"
			t.Message = err.Error()
			return
		}
	} //end if
	return
}
func HttpInterfaceReqWeb(postUrl string, data ...interface{}) (t *TBaseResultsWeb) {
	t = new(TBaseResultsWeb)
	t.B = true
	client := NewHttpClient()
	client.ContentType = HttpContentTypeJson
	client.Method = fasthttp.MethodPost
	client.TimeOut = timeOut
	message := client.HttpRequestRetry(postUrl, data...)
	xxlog.InfoUp366("HttpInterfaceReq", postUrl, message)
	t.HttpCode = message.Code
	if message.Err != nil {
		t.B = false
		t.Code = "error"
		t.Msg = message.Err.Error()
		return
	} else {
		if err := sonic.UnmarshalString(message.Body, &t); err != nil {
			t.B = false
			t.Code = "error"
			t.Msg = err.Error()
			return
		}
	} //end if
	if gconv.Int64(t.Code) == 1 {
		t.B = false
		t.Code = "error"
	} else {
		t.Code = "success"
	}
	//新的处理 end
	return
}
